import { createSlice } from "@reduxjs/toolkit";

const counterSlice = createSlice({
    name: "counter", // 模块名称
    initialState: { // 初始状态
        value: 10
    },
    // reducers: 用于定义 action 如何改变 state
    reducers: {
        increment: (state,action) => {
            state.value += action.payload;
        },
        decrement: (state,action) => {
            state.value -= action.payload;
        }
    },

});

// actions: 用于导出 action
export const { increment, decrement } = counterSlice.actions;

// reducer: 用于导出 reducer
export default  counterSlice.reducer;